home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 1 / CU Amiga Magazine CD-ROM Special Edition (1995)(EMAP Images)(GB)[Issue 1995-11].iso / Aminet / comm / tcp / AmiTCPsdk_40.lha / AmiTCP-4.0 / src / examples / rpc / dir / rls.c < prev    next >
C/C++ Source or Header  |  1994-03-09  |  2KB  |  80 lines

  1. /* @(#)rls.c    2.2 88/08/12 4.0 RPCSRC */
  2. /*
  3.  * rls.c: Remote directory listing client
  4.  */
  5. #include <stdio.h>
  6. #include <rpc/rpc.h>        /* always need this */
  7. #include "dir.h"        /* need this too: will be generated by rpcgen*/
  8.  
  9. extern int errno;
  10.  
  11. main(int argc, char **argv)
  12. {
  13.     CLIENT *cl;
  14.     char *server;
  15.     char *dir;
  16.     readdir_res *result;
  17.     namelist nl;
  18.     
  19.  
  20.     if (argc != 3) {
  21.         fprintf(stderr, "usage: %s host directory\n", argv[0]);
  22.         exit(1);
  23.     }
  24.  
  25.     /*
  26.      * Remember what our command line arguments refer to
  27.      */
  28.     server = argv[1];
  29.     dir = argv[2];
  30.  
  31.     /*
  32.      * Create client "handle" used for calling DIRPROG on the
  33.      * server designated on the command line. We tell the rpc package
  34.      * to use the "tcp" protocol when contacting the server.
  35.      */
  36.     cl = clnt_create(server, DIRPROG, DIRVERS, "tcp");
  37.     if (cl == NULL) {
  38.         /*
  39.          * Couldn't establish connection with server.
  40.          * Print error message and die.
  41.          */
  42.         clnt_pcreateerror(server);
  43.         exit(1);
  44.     }
  45.     
  46.     /*
  47.      * Call the remote procedure "readdir" on the server
  48.      */
  49.     result = readdir_1(&dir, cl);
  50.     if (result == NULL) {
  51.         /*
  52.          * An error occurred while calling the server. 
  53.           * Print error message and die.
  54.          */
  55.         clnt_perror(cl, server);
  56.         exit(1);
  57.     }
  58.  
  59.     /*
  60.      * Okay, we successfully called the remote procedure.
  61.      */
  62.     if (result->errno != 0) {
  63.         /*
  64.          * A remote system error occurred.
  65.          * Print error message and die.
  66.          */
  67.         errno = result->errno;
  68.         perror(dir);
  69.         exit(1);
  70.     }
  71.  
  72.     /*
  73.      * Successfuly got a directory listing.
  74.      * Print it out.
  75.      */
  76.     for (nl = result->readdir_res_u.list; nl != NULL; nl = nl->next) {
  77.         printf("%s\n", nl->name);
  78.     }
  79. }
  80.